import {action, observable} from 'mobx'
import {axiosFetch, handleResp} from "../../util/common/http";

export class UserCenterStore {
	@observable userInfo: {
		userId: string,
		userPhoto: string|null,
		userNickName: string,
		userPhone: string,
	}|null = null;

	// 用户状态(1:可编辑 0:用户不存在or出错了)
	@observable userStatus: number = 1;

	/**
	 * 获取登录人基本信息
	 */
	@action initUserInfo = async () => {
		const fetchResp = await axiosFetch("/user/login/query", {
			method: 'GET'
		});
		if (handleResp(fetchResp)) {
			this.userInfo = fetchResp.context;
		} else {
			this.userStatus = 0;
		}
	};

}

export default new UserCenterStore();
